package com.kgc.community.service.impl;

import com.kgc.community.mapper.*;
import com.kgc.community.pojo.*;
import com.kgc.community.service.CostService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Mr.Man
 * @Date 2020-11-29 13:19
 **/
@Service
public class CostServiceImpl implements CostService {
    @Resource
    CostMapper costMapper;
    @Resource
    CostCountMapper costCountMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    RoomUserMapper roomUserMapper;

    @Resource
    RoomsMapper roomsMapper;

    @Override
    public List<CostCount> selectAll() {
        List<CostCount> costCounts = costCountMapper.selectByExample(null);
        return costCounts;
    }

    @Override
    public List<Cost> selectByTypeId(Integer typeId) {
        CostExample costExample = new CostExample();
        costExample.createCriteria().andTypeIdEqualTo(typeId);
        List<Cost> costs = costMapper.selectByExample(costExample);
        return costs;
    }

    @Override
    public List<Rooms> selectNoBytypeId() {
        List<Rooms> rooms = roomsMapper.selectByExample(null);
        for (int i = 0; i < rooms.size(); i++) {
            if(rooms.get(i).getStatus()==0){
                rooms.remove(i);
            }
        }
        return rooms;
    }

    @Override
    public Integer insert(Cost cost) {
        int i = costMapper.insertSelective(cost);
        System.out.println(cost.getId());
        return cost.getId();
    }

    @Override
    public List<Cost> selectBycid(Integer id) {
        CostExample costExample = new CostExample();
        costExample.createCriteria().andTypecoutEqualTo(id);
        List<Cost> costs = costMapper.selectByExample(costExample);
        return costs;
    }

    @Override
    public List<RoomUser> selectById(Integer id) {
        RoomUserExample roomUserExample = new RoomUserExample();
        roomUserExample.createCriteria().andRoomIdEqualTo(id.toString());
        List<RoomUser> roomUsers = roomUserMapper.selectByExample(roomUserExample);
        return roomUsers;
    }

    @Override
    public Integer updateType(Integer id) {
        System.out.println(id+"内部测试");
        Cost cost = new Cost();
        cost.setId(id);
        cost.setCost((long) 1);
        int i = costMapper.updateByPrimaryKeySelective(cost);
        return i;
    }


}
